<?php
session_start();
include 'conn.php';

$flag=0;

 ?>
<!DOCTYPE>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<!-- <link rel="icon" href="./images/icon.ico"> -->
		<link rel="stylesheet" type="text/css" href="./css/general.css">
		<link rel="stylesheet" type="text/css" href="./css/index.css">
		<script type="text/javascript" src="./js/jquery.js"></script>
		<script type="text/javascript" src="./js/general.js"></script>
		<script type="text/javascript" src="./js/carousel.js"></script>
		<title></title>
	</head>
	
	<body>
		<!-- 顶部开始 -->
		<!-- 头部开始 -->
		<?php include 'header.php'; ?>
		
		
		
		
		
		<!-- 主体开始 -->
		<div class="container w1100">
			<div class="module cut">
				<!-- 商品分类开始 -->
				<div class="catebar w210 fl">
			
				</div>
				
	
				
				<!-- 商品分类结束 -->
				<!-- 轮播图片广告开始 -->
				<div class="w640 fl cut">
					<div class="carousel cut">
						<p style="font-size:30px">
							轮播图
						</p>
						<div class="carousel-imgs cut">
							<?php
							  $sql = "select * from adv";

							  $result = $conn->query($sql);
							  if ($result->num_rows>0) {
								$count = $result->num_rows;
								while ($row=$result->fetch_assoc()) {
?>
								<a href="<?php echo $row['link']?>" style="display: block;">
									<img src="<?php echo $row['picture']?>" width="800" height="340" border="0">
								</a>
							<?php
								}
								?>

							<ul class="carousel-tog">
								<?php
									while ($count>0) {
									  ?>
										<li class="cur"><?php echo $count ?></li>
										<?php
									  $count -= 1;
									}
							 ?>
							</ul>
							<?php
							  }
							 ?>
						</div>
					</div>
				</div>
				<!-- 轮播图片广告结束 -->
			</div>
			
			<!-- 广告区域开始 -->
			<!-- 广告区域开始 -->
			<!-- 广告区域开始 -->
			<div class="advertising-area">
			    <div class="w1100">
			        <div class="gli_t">
			            <h2 class="fl">广告展览</h2>
			            <br />
			            <br />
			            <br />
			        </div>
			        <hr />
			        <div class="ad-container">
			            <?php
			            // 查询广告数据
			            $sql = "SELECT * FROM adv";
			            $result = $conn->query($sql);
			
			            if ($result->num_rows > 0) {
			                // 输出每条广告数据
			                while($row = $result->fetch_assoc()) {
			                    echo '<div class="ad-item">';
			                    echo '<a href="' . htmlspecialchars($row['link']) . '" target="_blank">';
			                    echo '<img src="' . htmlspecialchars($row['picture']) . '" alt="' . htmlspecialchars($row['name']) . '" class="ad-image">';
			                    echo '</a>';
			                    echo '<p class="ad-name">' . htmlspecialchars($row['name']) . '</p>';
			                    echo '</div>';
			                }
			            } else {
			                echo "<div class='ad-item'>没有广告数据</div>";
			            }
			
			            ?>
			        </div>
			    </div>
			</div>
			<!-- 广告区域结束 -->
			<!-- 广告区域结束 -->
			<!-- 广告区域结束 -->
			<br />
			<br />
			<br />
			
			<!-- 文章列表区域开始 -->
			<div  class="articles-area">
				<div class="w1100">
					<div class="gli_t">
						<h2 class="fl">公司文化展览</h2>
						<br />
						<br />
						<br />
					</div>
					<hr />
					<div class="articles-container">
						<?php
						// 查询文章数据
						$sql_articles = "SELECT * FROM wenzhang ORDER BY time DESC";
						$result_articles = $conn->query($sql_articles);
			
						if ($result_articles->num_rows > 0) {
							// 输出每篇文章数据
							while($row_article = $result_articles->fetch_assoc()) {
								echo '<div class="article-item">';
								echo '<h2><a href="article.php?wzid=' . $row_article['id'] . '">' . htmlspecialchars($row_article['title']) . '</a></h2>';
								echo '<p>作者：' . htmlspecialchars($row_article['author']) . '</p>';
								echo '<p>发布时间：' . date('Y-m-d H:i:s', strtotime($row_article['time'])) . '</p>';
								echo '<p>' . mb_strimwidth(strip_tags($row_article['content']), 0, 200, "...") . '</p>';
								echo '<a href="article.php?wzid=' . $row_article['id'] . '" class="read-more">阅读更多</a>';
								echo '</div>';
							}
						} else {
							echo "没有文章数据";
						}
						?>
					</div>
				</div>
			</div>
			<!-- 文章列表区域结束 -->
			<!-- 推荐商品 -->
			<div class="module mt30 cut">
			    <div class="gli_t">
			        <h2 class="fl">推荐商品</h2>
					<br />
					<br />
					<br />
			    </div>
				<hr />
			    <div class="gli w1110">
			        <ul class="product-list">
			            <?php
			            $sql = "SELECT * FROM goods where type = 1";
			            $result = $conn->query($sql);
			            if ($result->num_rows > 0) {
			                // 输出每行数据
			                while ($row = $result->fetch_assoc()) {
			            ?>
			                <li class="product-item">
			                    <div class="product-card">
			                        <div class="im">
			                            <a href="goods.php?id=<?php echo $row["id"];
			                                if ($flag == 1) {
			                                    echo '&uid='.$uid;
			                                }
			                                ?>">
			                                <img src="<?php echo $row['picture']; ?>" alt="商品图片" class="card-image">
			                            </a>
			                        </div>
			                        <div class="product-details">
			                            <h3 class="card-title">
			                                <a href="goods.php?id=<?php echo $row["id"];
			                                    if ($flag == 1) {
			                                        echo '&uid=' . $uid;
			                                    }
			                                    ?>">
			                                    <?php echo $row["goods_name"]; ?>
			                                </a>
			                            </h3>
			                            <del>
			                                <p class="card-price-old">原价 ¥<?php echo $row["old_price"]; ?></p>
			                            </del>
			                            <p class="card-price-new">现价 ¥<?php echo $row["price"]; ?></p>
			                        </div>
			                    </div>
			                </li>
			            <?php
			                }
			            } else {
			                echo "0 个结果";
			            }
			            ?>
			        </ul>
			    </div>
			</div>
			
			
			
			<!-- 热门商品 -->
			<div class="module mt30 cut">
			    <div class="gli_t">
			        <h2 class="fl">热门商品</h2>
					<br />
					<br />
					<br />
			    </div>
				<hr />
			    <div class="gli w1110">
			        <ul class="product-list">
			            <?php
			            $sql = "SELECT * FROM goods where type = 2";
			            $result = $conn->query($sql);
			            if ($result->num_rows > 0) {
			                // 输出每行数据
			                while ($row = $result->fetch_assoc()) {
			            ?>
			                <li class="product-item">
			                    <div class="product-card">
			                        <div class="im">
			                            <a href="goods.php?id=<?php echo $row["id"];
			                                if ($flag == 1) {
			                                    echo '&uid='.$uid;
			                                }
			                                ?>">
			                                <img src="<?php echo $row['picture']; ?>" alt="商品图片" class="card-image">
			                            </a>
			                        </div>
			                        <div class="product-details">
			                            <h3 class="card-title">
			                                <a href="goods.php?id=<?php echo $row["id"];
			                                    if ($flag == 1) {
			                                        echo '&uid=' . $uid;
			                                    }
			                                    ?>">
			                                    <?php echo $row["goods_name"]; ?>
			                                </a>
			                            </h3>
			                            <del>
			                                <p class="card-price-old">原价 ¥<?php echo $row["old_price"]; ?></p>
			                            </del>
			                            <p class="card-price-new">现价 ¥<?php echo $row["price"]; ?></p>
			                        </div>
			                    </div>
			                </li>
			            <?php
			                }
			            } else {
			                echo "0 个结果";
			            }
			            ?>
			        </ul>
			    </div>
			</div>
			<!-- 热门商品结束 -->
			
			
			<!-- 最新商品 -->
			<div class="module mt30 cut">
			    <div class="gli_t">
			        <h2 class="fl">最新商品</h2>
					<br />
					<br />
					<br />
			    </div>
				<hr />
			    <div class="gli w1110">
			        <ul class="product-list">
			            <?php
			            $sql = "SELECT * FROM goods where type = 3";
			            $result = $conn->query($sql);
			            if ($result->num_rows > 0) {
			                // 输出每行数据
			                while ($row = $result->fetch_assoc()) {
			            ?>
			                <li class="product-item">
			                    <div class="product-card">
			                        <div class="im">
			                            <a href="goods.php?id=<?php echo $row["id"];
			                                if ($flag == 1) {
			                                    echo '&uid='.$uid;
			                                }
			                                ?>">
			                                <img src="<?php echo $row['picture']; ?>" alt="商品图片" class="card-image">
			                            </a>
			                        </div>
			                        <div class="product-details">
			                            <h3 class="card-title">
			                                <a href="goods.php?id=<?php echo $row["id"];
			                                    if ($flag == 1) {
			                                        echo '&uid=' . $uid;
			                                    }
			                                    ?>">
			                                    <?php echo $row["goods_name"]; ?>
			                                </a>
			                            </h3>
			                            <del>
			                                <p class="card-price-old">原价 ¥<?php echo $row["old_price"]; ?></p>
			                            </del>
			                            <p class="card-price-new">现价 ¥<?php echo $row["price"]; ?></p>
			                        </div>
			                    </div>
			                </li>
			            <?php
			                }
			            } else {
			                echo "0 个结果";
			            }
			            ?>
			        </ul>
			    </div>
			</div>
			<!-- 热门商品结束 -->
				
			
			
		</div>

<?php include 'footer.php'; ?>
</body>
			